package com.baizhi.cmfz.service.impl;

import com.baizhi.cmfz.dao.BannerDao;
import com.baizhi.cmfz.entiy.Banner;
import com.baizhi.cmfz.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class BannerServiceImpl implements BannerService {

    @Autowired
    private BannerDao dao;
    @Override
    public Map selectAllBanner(int page, int rows, String bannerName) {

        Map map = new HashMap();
        //若用户名不等于null和空串
        if(bannerName!=null && !"".equals(bannerName)){
            bannerName="%"+bannerName+"%";//在java代码中拼接好，可以屏蔽数据库的差异
        }else{
            bannerName=null;
        }

        int total = dao.getTotal(bannerName);
        map.put("total", total);

        int start=(page-1)*rows;
        int pageSize=rows;
        List<Banner> list = dao.selectAllBanner(start,pageSize,bannerName);

        map.put("rows", list);
        //System.out.println(map);
        return map;
    }

    @Override
    public void add(Banner banner) {
        dao.insert(banner);
    }
    public void update(Banner banner){
        dao.update(banner);
    }

}
